#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}


string w[8] = {"", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

inline void solution() {
    string s1, s2;
    getline(cin, s1);
    getline(cin, s2);
    bool first = false;
    int week, hour, min; 
    for (int i = 0; i < s1.size() && i < s2.size(); i ++ ) 
    {
        if (!first && s1[i] == s2[i] && s1[i] >= 'A' && s1[i] <= 'G')
            week = s1[i] - 'A' + 1, first = true;
        else if (first && s1[i] == s2[i] && (s1[i] >= '0' && s1[i] <= '9' || s1[i] >= 'A' && s1[i] <= 'N' ))
        {
            if (s1[i] >= '0' && s1[i] <= '9')
                hour = s1[i] - '0';
            else
                hour = s1[i] - 'A' + 10;
            break;
        }
    }
    getline(cin, s1);
    getline(cin, s2);
    for (int i = 0; i < s1.size() && i < s2.size(); i ++ ) 
        if (s1[i] == s2[i] && (s1[i] >= 'a' && s1[i] <= 'z' || s1[i] >= 'A' && s1[i] <= 'Z'))
        {
            min = i;
            break;
        }
    printf("%s %02d:%02d\n" , w[week].c_str(), hour, min);
//     cout << w[week] << " " << hour << ":" << min << endl;
    return ;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}